using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Beta_fundies_controls_quotes_EditQuoteForm : Controls.DataManagerQuoteControl
{
    protected override void ItemChanged()
    {
        if (CurrentQuote != null)
        {
            mviewQuote.SetActiveView(viewEdit);
            txtBoard.Text = CurrentQuote.Board;
            txtFundie.Text = CurrentQuote.Fundie;
            txtNumberOfVoters.Text = CurrentQuote.NumberOfVoters.ToString();
            txtQuote.Text = CurrentQuote.FundieQuote;
            txtTotalVotes.Text = CurrentQuote.TotalVotes.ToString();
            txtUrl.Text = CurrentQuote.URL;
            txtContributor.Text = CurrentQuote.Contributor;
            chkCreditContributor.Checked = CurrentQuote.CreditContributor;
            ddlArchive.SelectedValue = CurrentQuote.Archive.ID.ToString();
        }
        else
        {
            mviewQuote.SetActiveView(viewError);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ddlArchive.DataSource = DAL.Archives.All();
            ddlArchive.DataBind();
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            CurrentQuote.Board = txtBoard.Text;
            CurrentQuote.Fundie = txtFundie.Text;
            CurrentQuote.NumberOfVoters = Convert.ToInt32(txtNumberOfVoters.Text);
            CurrentQuote.FundieQuote = txtQuote.Text;
            CurrentQuote.TotalVotes = Convert.ToInt32(txtTotalVotes.Text);
            CurrentQuote.URL = txtUrl.Text;
            CurrentQuote.Contributor = txtContributor.Text;
            CurrentQuote.CreditContributor = chkCreditContributor.Checked;

            long id;
            if (Int64.TryParse(ddlArchive.SelectedValue, out id))
            {
                CurrentQuote.Archive = DAL.Archives.Item(id);
            }
            DAL.Quotes.Save(CurrentQuote);
            lblMsg.Visible = true;
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = Uri.IsWellFormedUriString(args.Value, UriKind.Absolute);
    }
}
